/**
 * this should come from a config file
 * Ideally we could have an object with all needed variables of an institution parameterized;
 * wms server, tilecaching server, download server, source graphic...what else? resolutions array for tile caching?
 */

if (typeof org === 'undefined'){ 
	org = {};
} else if (typeof org !== "object"){
	throw new Error("org already exists and is not an object");
}

// Repeat the creation and type-checking code for the next level
if (typeof org.OpenGeoPortal === 'undefined'){
	org.OpenGeoPortal = {};
} else if (typeof org.OpenGeoPortal !== "object"){
    throw new Error("org.OpenGeoPortal already exists and is not an object");
}
org.OpenGeoPortal.institution = "Tufts";

org.OpenGeoPortal.InstitutionInfo =
{
"Tufts": {"servers": {"WMS": ["http://geoserver-dev.atech.tufts.edu/wms"],
			"tileCache": ["http://geoserver-dev.atech.tufts.edu/gwc/service/wms"],
			"download": ["http://geoserver-dev.atech.tufts.edu/wfs"],
			"search": {"url": "geoportal-demo.atech.tufts.edu", "port": 80}},
	"graphics": {"sourceIcon": "<img src=\"media/src_tufts.png\" alt=\"Tufts\" title=\"Tufts University\" />"}},
"MIT": {"servers": {"WMS": ["http://arrowsmith.mit.edu:8080/geoserver/wms"],
		"tileCache": ["http://arrowsmith.mit.edu:8080/geoserver/gwc/service/wms"],
		"download": ["https://arrowsmith.mit.edu/geoweb/php_scripts/shpDownloadDirect.php"]},
	"graphics": {"sourceIcon": "<img src=\"media/src_mit.png\" alt=\"MIT\" title=\"Massachusetts Institute of Technology\" />"}},
"Harvard": {"servers": {"WMS": ["http://dixon.hul.harvard.edu:8080/geoserver/wms"],
		"tileCache": ["http://dixon.hul.harvard.edu/cgi-bin/tilecache/tilecache.cgi"],
		"download": ["http://dixon.hul.harvard.edu:8080/geoserver/wfs"],
		"search": {"url": "pynchon.hul.harvard.edu", "port": 8080}},
	"graphics": {"sourceIcon": "<img src=\"media/src_harvard.png\" alt=\"Harvard\" title=\"Harvard University\" />"}},
"Princeton": {"servers": {"WMS": [""],
		"tileCache": [""],
		"download": [""]},
	"graphics": {"sourceIcon": "<img src=\"media/src_princeton.png\" alt=\"Princeton\" title=\"Princeton University\" />"}},
"MassGIS": {"servers": {"WMS": ["http://giswebservices.massgis.state.ma.us/geoserver/wms"],
		"tileCache": ["http://giswebservices.massgis.state.ma.us/geoserver/wms"],
		"download": ["http://giswebservices.massgis.state.ma.us/geoserver/wfs"]},
	"graphics": {"sourceIcon": "<img src=\"media/src_cambridge.png\" alt=\"MassGIS\" title=\"MassGIS\" />"}}
};

org.OpenGeoPortal.InstitutionInfo.tilecacheToWMS =  function(tilingUrl){
	var institutionInfo = org.OpenGeoPortal.InstitutionInfo;
	for (var institution in institutionInfo){
		var currentInstitution = institutionInfo[institution].servers;
		if (tilingUrl == currentInstitution.WMS){
			return tilingUrl;
		} else if (tilingUrl == currentInstitution.tileCache) {
			return currentInstitution.WMS;
		}
	}
};